package com.Tadama.Forms;

import com.Tadama.MIDlet.TadamaMIDlet;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import com.Tadama.Forms.frmBuscarClientes;
import com.Tadama.Utility.CommandBuilder;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.ImageItem;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.StringItem;
import javax.microedition.lcdui.TextField;
import javax.microedition.lcdui.Ticker;
import org.netbeans.microedition.lcdui.SimpleTableModel;
import org.netbeans.microedition.lcdui.TableItem;
import org.netbeans.microedition.lcdui.TableModel;

public class frmDevolucion extends Form implements CommandListener{
    private TadamaMIDlet mainMidlet;
    private Displayable previousDisplay;
    private Alert alerta;
    
    private StringItem stCliente;
    private Ticker ticker;
    private TableItem tblProductos;
    private SimpleTableModel Tabla;
    
    private static final Command cmConfirmar = CommandBuilder.getOk();
    private static final Command cmCancelar = CommandBuilder.getCancel();
    
    public frmDevolucion(TadamaMIDlet mainMIDlet, Displayable previousDisplay) {
        super("Devolucion");
        this.mainMidlet=mainMIDlet;
        this.previousDisplay=previousDisplay;
        
        stCliente= new StringItem("Cliente: ", "Bodega Pepito", StringItem.BUTTON);
        ticker = new Ticker("GPS:ON -Latitud: 152.92517 || Longitud: 054.27365");
        Tabla = new SimpleTableModel(4, 3);
        
        for(int i=0;i<3;i++)
        {
            for(int j=0;j<4;j++)
            {
                if(i==0) Tabla.setValue(i, j, "Producto: "+ j);
                if(i==1) Tabla.setValue(i, j, "3");
                if(i==2) Tabla.setValue(i, j, "Cajas");
            }
        }
        Tabla.setColumnNames(new java.lang.String[]{"Producto", "Cantidad", "Unidad"});
        tblProductos = new TableItem(getDisplay(), null);
        tblProductos.setPreferredSize(-1, -1);
        tblProductos.setLayout(ImageItem.LAYOUT_NEWLINE_AFTER | ImageItem.LAYOUT_NEWLINE_BEFORE|ImageItem.LAYOUT_RIGHT|ImageItem.LAYOUT_LEFT);
        tblProductos.setTitle("Productos Seleccionados");
        tblProductos.setModel(Tabla);
        this.append(stCliente);
        this.append(tblProductos);
        this.setTicker(ticker);
        this.addCommand(cmCancelar);
        this.addCommand(cmConfirmar);
        this.setCommandListener(this);
    }
    public Display getDisplay() {
        return Display.getDisplay(this.mainMidlet);
    }
    public Alert getAlert() {
        if (alerta == null) {
            alerta = new Alert("Confirmacion", "Devolicion Registrado Satisfactriamente", null, AlertType.CONFIRMATION);
            alerta.addCommand(cmConfirmar);
            alerta.setCommandListener(this);
            alerta.setTimeout(Alert.FOREVER);
        }
        return alerta;
    }
    public void commandAction(Command c, Displayable d) {
        if(d==this){
            if(c==cmConfirmar){
                Display.getDisplay(mainMidlet).setCurrent(getAlert(), this);
            }
            if(c==cmCancelar){
                Display.getDisplay(mainMidlet).setCurrent(new lstMenu(mainMidlet, "Menu Principal",List.IMPLICIT));
            }
        }
        if (d==alerta)
        {
            if(c == cmConfirmar)
                Display.getDisplay(mainMidlet).setCurrent(new lstMenu(mainMidlet,"Menu Principal",List.IMPLICIT));
        }
    }
    
}
